Using Two GPIO Actions in Oneshot mode
This is a continuation from the Stopping a Robot if It Tips Over example. In this page, we'll set up an additional threshold trigger and GPIO action which will perform the E-stop "reset" function.
NOTE: This example can be easily adapted to the 3DM-CV7 by substituting GPIO 1 or GPIO 2 for GPIO 4.
GPIO Action #2
We'll set up a second GPIO action which will restore the pin to the inactive, low state. This action must have a different instance ID, use the opposite polarity oneshot mode, and reference a new trigger ID.
Command: Event Action Configuration (0x0C,0x2F)
- Function: WRITE (0x01)
- Instance: 2 (must be different from the original)
- Trigger ID: 2 (must match trigger config below and should not be the first trigger)
- Type: GPIO (0x01)
- Parameters:
- Pin: 4 (the same pin)
- Mode: ONESHOT_LOW (0x06)
Command bytes: 010202010406
MIP Packet: 75650c08 082f010202010406 3545
Threshold Trigger #2
We'll set up another threshold trigger just like the first but with a narrower window and the opposite logic. This will trigger when the robot is returned to the upright position, plus or minus 10 degrees. The trigger will be similar to the original one, but have a different instance ID, different thresholds, and reversed logic.
Command: Event Trigger Configuration (0x0C,0x2E)
- Function: WRITE (0x01)
- Instance: 2 (must be different from the original)
- Type: Threshold (0x02)
- Parameters:
- Descriptor Set: 0x80 (Sensor Dataset)
- Field Descriptor: 0x0C (Euler Angles)
- Parameter ID: 1 (Roll)
- Mode: WINDOW (0x01)
- Low Threshold: -0.1745329 (-10 degrees)
- High Threshold: +0.1745329 (+10 degrees)
Command bytes: 010202800c0101bfc6571814c9bba03fc6571814c9bba0
MIP Packet: 75650c19 192e010202800c0101bfc6571814c9bba03fc6571814c9bba0 b1fa
Enable the trigger
Command: Event Control (0x0C,0x2B)
- Function: WRITE (0x01)
- Instance: 2
- Mode: ENABLE (0x01)
Command bytes: 010201
MIP Command: 75650c05 052b010201 1f84
Test it
Now tilt the 3DM-CV7 as before. The buzzer should sound but once the device is returned to level it should stop.